Skip to content
This repository has been archived by the owner on May 7, 2020. It is now read-only.

core/ConfigUtil: Do not normalize objectClass, component.name, component.id configuration values #4109

Merged
merged 1 commit into from
Aug 24, 2017

Conversation

davidgraeff
Copy link
Contributor

The class ConfigUtil is used by Configuration to normalize values of a given Map<String,Object> configuration map.

I started to use Configuration recently also in OSGi services (in the activate and modified method), not only ThingHandlers, which works wonderfully. Except that I get a lot of warnings of the aforementioned class because it tries to normalize "objectClass" which is a complex object.

To be able to use the Configuration class like in the example below, the "objectClass" and two other OSGi default configuration parameters should be excluded.

    @Modified
    protected void modified(Map<String, Object> config) {
        configuration= new Configuration(config).as(NetworkBindingConfiguration.class);
    }

Signed-off-by: David Gräff david.graeff@web.de

@sjsf
Copy link
Contributor

sjsf commented Aug 22, 2017

That clearly makes sense!

I'm just wondering whether this is the right/only place for this check... On the first glance there also is the normalizeTypes(Map<String, Object>, List<ConfigDescription>) which could suffer from the same bug, couldn't it?

In any case, I think putting this assertion into ConfigUtilTest to make sure it doesn't get broken by anybody accidentally would make sense.

@davidgraeff
Copy link
Contributor Author

I cannot open projects with groovy code unfortunately, something is misconfigured in my eclipse. I converted one of the test suites to java but converting everything is a little tedious to just have this merged.

Copy link
Contributor

@sjsf sjsf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I converted one of the test suites to java but converting everything is a little tedious

Fully ack, it's great like that, thanks! Better don't repair your IDE then... 😉

@@ -138,8 +135,10 @@ public static Object normalizeType(Object value, ConfigDescriptionParameter conf
for (Entry<String, ?> parameter : configuration.entrySet()) {
String name = parameter.getKey();
Object value = parameter.getValue();
ConfigDescriptionParameter configDescriptionParameter = configParams.get(name);
convertedConfiguration.put(name, normalizeType(value, configDescriptionParameter));
if (!name.equals("objectClass") && !name.equals("component.name") && !name.equals("component.id")) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that I'm seeing this, I think it would be good to have a static set of strings defined once, then checking here (and above) only if the name is contained in there - just to make sure they don't run out of sync.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about a private helper method instead?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure, even better

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

…ent.id configuration values

Signed-off-by: David Gräff <david.graeff@web.de>
for (Entry<String, Object> parameter : configuration.entrySet()) {
String name = parameter.getKey();
Object value = parameter.getValue();
convertedConfiguration.put(name, normalizeType(value));
if (!isOSGiConfigParameter(name)) {
convertedConfiguration.put(name, normalizeType(value));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You only add the value to your convertedConfiguration if it is not an OSGI parameter, is that by intention or is there an

else {
    convertedConfiguration.put(name, value);
}

missing?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes that's the entire purpose of this PR, to ignore the OSGi parameters completely. They contain either dots so cannot be matched with a variable name or are complex objects, so cannot be marshaled to values.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 - these values don't make any sense for the service itself. It knows its name and pid.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah Ok, then the name of this PR was a bit misleading for me, because it soudned like you only want to omit the "normalization" and not the entire parameters. thanks for the clarification!

convertedConfiguration.put(name, normalizeType(value, configDescriptionParameter));
if (!isOSGiConfigParameter(name)) {
ConfigDescriptionParameter configDescriptionParameter = configParams.get(name);
convertedConfiguration.put(name, normalizeType(value, configDescriptionParameter));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above, don't you want to add an (un-normalized) OSGI parameter to your return map?

@sjsf sjsf merged commit e5b930a into eclipse-archived:master Aug 24, 2017
@sjsf
Copy link
Contributor

sjsf commented Aug 24, 2017

Thanks!

@davidgraeff davidgraeff deleted the configutil branch August 24, 2017 06:34
@kaikreuzer kaikreuzer added this to the 0.9.0 milestone Nov 30, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants